package cn.itcast.account.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * AccountTccService:使用分布式事务TCC模式
 * try：
 * confirm：事务提交
 * cancel：事务回滚
 */
@LocalTCC
public interface AccountTccService {

    /**
     * 1.deduct：扣减金额的方法
     * @TwoPhaseBusinessAction标注的方法就是try
     * @BusinessActionContextParameter标注的参数,可以在BusinessActionContext中获取
     *
     * @param userId
     * @param money
     */
    @TwoPhaseBusinessAction(name = "deduct",commitMethod = "confirm",rollbackMethod = "cancel")
    void deduct(@BusinessActionContextParameter(paramName = "userId") String userId,
                @BusinessActionContextParameter(paramName = "money") int money);

    /**
     * 2.confirm：事务提交
     * @param context
     * @return
     */
    boolean confirm(BusinessActionContext context);

    /**
     * 3.cancel：事务回滚
     * @param context
     * @return
     */
    boolean cancel(BusinessActionContext context);
}
